home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Menus.c
-
- Contains: Handles the application's menus
-
- Written by: Chris White, Developer Technical Support
-
- Copyright: © 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- 1/22/96 CW First release
-
- */
-
-
- #pragma segment Core
-
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #ifndef __DESK__
- #include <Desk.h>
- #endif
-
-
-
-
-
- // Application includes
-
- #ifndef __BAREBONES__
- #include "BareBones.h"
- #endif
-
- #ifndef __PROTOTYPES__
- #include "Prototypes.h"
- #endif
-
-
-
-
-
- // static includes
-
- static void DoAppleCmds ( SInt16 theMenu, SInt16 theItem );
- static void DoFileCmds ( SInt16 theMenu, SInt16 theItem );
- static void DoProgressBarsCmds ( SInt16 theMenu, SInt16 theItem );
- static Boolean EnableFileCmds ( WindowRef frontWindow );
- static Boolean EnableProgressBarsCmds ( WindowRef frontWindow );
-
- static void SetItemEnable ( MenuHandle theMenu, SInt16 theItem, Boolean bEnabled );
-
-
-
-
-
- void MenuDispatch ( SInt32 menuResult )
- {
- SInt16 theMenu = (menuResult >> 16); // menu selected
- SInt16 theItem = (menuResult & 0x0000FFFF); // item selected
-
- switch (theMenu)
- {
- case kAppleMenu:
- DoAppleCmds ( theMenu, theItem );
- break;
-
- case kFileMenu:
- DoFileCmds ( theMenu, theItem );
- break;
-
- case kProgressBarsMenu:
- DoProgressBarsCmds ( theMenu, theItem );
- break;
-
- }
-
- HiliteMenu ( 0 ); // un-hilite selected menu
-
- return;
-
- } // MenuDispatch
-
-
-
- void AdjustMenus ( void )
- {
- Boolean bRedraw = false;
- WindowRef frontWindow;
-
- frontWindow = FrontWindow ( );
- if ( EnableFileCmds ( frontWindow ) )
- bRedraw = true;
- if ( EnableProgressBarsCmds ( frontWindow ) )
- bRedraw = true;
-
- if ( bRedraw )
- DrawMenuBar ( );
-
- return;
-
- } // AdjustMenus
-
-
-
- static void DoAppleCmds ( SInt16 theMenu, SInt16 theItem )
- {
- Str255 name; // string for DA name
-
-
- switch ( theItem )
- {
- case cAbout:
- Alert ( kAboutDialog, nil );
- break;
-
- default:
- GetMenuItemText ( GetMenuHandle ( kAppleMenu ), theItem, (StringPtr) &name );
- OpenDeskAcc ( (StringPtr) &name );
- break;
- }
-
- return;
-
- } // DoAppleCmds
-
-
-
- static void DoFileCmds ( SInt16 theMenu, SInt16 theItem )
- {
- switch ( theItem )
- {
- case cQuit:
- gQuit = true;
- break;
- }
-
- return;
-
- } // DoFileCmds
-
-
-
- static void DoProgressBarsCmds ( SInt16 theMenu, SInt16 theItem )
- {
- OSErr theErr = noErr;
- Str255 theText;
- static Boolean bUseThreads = false;
-
-
- switch ( theItem )
- {
- case cToggleThreads:
- bUseThreads = !bUseThreads;
- CheckItem ( GetMenuHandle ( theMenu ), theItem, bUseThreads );
- break;
-
- case cStandard:
- GetIndString ( theText, kMiscStrings, kProgressStr );
- if ( bUseThreads )
- theErr = ThreadedProgressOperation ( ThreadedStandardDemoOperation, nil,
- theText, nil, false );
- else
- theErr = ProgressOperation ( StandardDemoOperation, nil, theText );
- break;
-
- case cBarberPole:
- GetIndString ( theText, kMiscStrings, kProgressStr );
- if ( bUseThreads )
- theErr = ThreadedProgressOperation ( ThreadedBarberPoleDemoOperation, nil,
- theText, nil, true );
- else
- theErr = ProgressOperation ( BarberPoleDemoOperation, nil, theText );
- break;
- }
-
- if ( theErr )
- AlertUser ( kGenericErrorStr, theErr, "\p" );
-
- return;
-
- } // DoProgressBarsCmds
-
-
-
- static Boolean EnableFileCmds ( WindowRef frontWindow )
- {
- static Boolean bIsEnabled = true;
- Boolean bHasDialog = false;
- Boolean bUpdate = false;
- MenuHandle theMenu = GetMenuHandle ( kFileMenu );
-
-
- bHasDialog = frontWindow && GetWindowKind ( frontWindow ) == dialogKind;
-
- if ( bIsEnabled == bHasDialog ) // Or bIsEnabled != !bHasDialog
- {
- SetItemEnable ( theMenu, 0, !bHasDialog );
- bIsEnabled = !bHasDialog;
- bUpdate = true;
- }
-
- SetItemEnable ( theMenu, cQuit, !bHasDialog );
-
- return bUpdate;
-
- } // EnableFileCmds
-
-
-
- static Boolean EnableProgressBarsCmds ( WindowRef frontWindow )
- {
- static Boolean bIsEnabled = true;
- Boolean bHasDialog = false;
- Boolean bUpdate = false;
- MenuHandle theMenu = GetMenuHandle ( kProgressBarsMenu );
-
-
- bHasDialog = frontWindow && GetWindowKind ( frontWindow ) == dialogKind;
-
- if ( bIsEnabled == bHasDialog ) // Or bIsEnabled != !bHasDialog
- {
- SetItemEnable ( theMenu, 0, !bHasDialog );
- bIsEnabled = !bHasDialog;
- bUpdate = true;
- }
-
- SetItemEnable ( theMenu, cToggleThreads, gHasThreadManager );
-
- return bUpdate;
-
- } // EnableProgressBarsCmds
-
-
-
- static void SetItemEnable ( MenuHandle theMenu, SInt16 theItem, Boolean bEnabled )
- {
- if ( theMenu )
- {
- if ( bEnabled )
- EnableItem ( theMenu, theItem );
- else
- DisableItem ( theMenu, theItem );
- }
-
- return;
-
- } // SetItemEnable
-
-
-
-
-
-